package com.origin.baselibrary.activity

import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class BaseActivity<out VB : ViewDataBinding>(var contentViewId: Int = 0) : AppCompatActivity() {
    lateinit var mContext: Context


    //加载布局
//    abstract fun getContentViewId(): Int

    val baseBinding: VB by lazy {
        DataBindingUtil.setContentView<VB>(this, contentViewId)
    }

    open fun before() {

    }

    open fun initSavedInstanceState(savedInstanceState: Bundle?) {

    }

    final override fun onCreate(savedInstanceState: Bundle?) {
        before()
        super.onCreate(savedInstanceState)

        mContext = baseBinding.root.context
        initSavedInstanceState(savedInstanceState)

        initUI()

        initDataBinding()

        initViewListening()

        pageLogical()

    }

    override fun onDestroy() {
        super.onDestroy()

    }

    //初始化布局中的View 颜色 形状 等样式
    protected abstract fun initUI()

    //初始化databing 数据
    open fun initDataBinding() {
    }

    //初始化view监听
    open fun initViewListening() {

    }

    //页面逻辑
    protected abstract fun pageLogical()
}
